//package com.zzyy.study.controller;
//
//import org.redisson.Redisson;
//import org.redisson.api.RLock;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.StringRedisTemplate;
//
//import java.util.List;
//import java.util.concurrent.ConcurrentHashMap;
//import java.util.concurrent.TimeUnit;
//
///**
// * Description:
// * <p>
// * ClassName: RedisTransaction
// * date: 2021/2/15 16:43
// *
// * @author zzjx
// * @version 1.0
// * @since JDK 1.8
// */
//public class RedisTransaction {
//    private final String REDIS_KEY = "redis-key";
//    //redis相应key 的value
//    private String value = "xxx";
//    @Autowired
//    private Redisson redisson;
//    @Autowired
//    StringRedisTemplate redisTemplate;
//
//    public void ReidsTransaction() {
//        RLock lock = redisson.getLock(REDIS_KEY);
//        try {
//
//            lock.lock(2, TimeUnit.MINUTES);
//            //业务逻辑
//        } catch (Exception e) {
//
//        } finally {
////            while (true){
////               redisTemplate.watch(REDIS_KEY);
////               if(value.equalsIgnoreCase(redisTemplate.opsForValue().get(REDIS_KEY))){
////                     redisTemplate.setEnableTransactionSupport(true);
////                     redisTemplate.multi();;
////                     redisTemplate.delete(REDIS_KEY);
////                   List<Object> list = redisTemplate.exec();
////                   if(list == null){
////                       //删除失败
////                       continue;
////                   }
////               }
////               //会报错误ERR EXEC without MULTI 但是我们第一行就行写了阿
////                // 原因是没有开启这一行 redisTemplate.setEnableTransactionSupport(true);
////               redisTemplate.unwatch();
////               break;
////
////            }
//            if (lock.isLocked()) {
//                if (lock.isHeldByCurrentThread()) {
//                    lock.unlock();
//                }
//            }
//        }
//    }
//}
